define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'course/order_sign/index' + location.search,
                    add_url: 'course/order_sign/add',
                    edit_url: 'course/order_sign/edit',
                    del_url: 'course/order_sign/del',
                    multi_url: 'course/order_sign/multi',
                    import_url: 'course/order_sign/import',
                    table: 'order_sign',
                }, queryParams: function (params) {
                    // 自定义搜索条件
                    var filter = params.filter ? JSON.parse(params.filter) : {};
                    var op = params.op ? JSON.parse(params.op) : {};
                    if (Config.order_id && Config.order_id != 'null') {
                        // console.log("order_id",Config.order_id)
                        filter.order_id = Config.order_id;
                        op.order_id = "=";
                    }
                    params.filter = JSON.stringify(filter);
                    params.op = JSON.stringify(op);
                    // console.log(params);
                    return params;
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                showExport: true,
                exportDataType: "auto",
                exportTypes: [ 'excel'],
                exportOptions: {
                    fileName: '签到管理导出_' + Moment().format("YYYY-MM-DD"),
                    preventInjection: false,
                    mso: {
                        onMsoNumberFormat: function (cell, row, col) {
                            return !isNaN($(cell).text()) ? '\\@' : '';
                        },
                    },
                    ignoreColumn: [0, 'operate'] //默认不导出第一列(checkbox)与操作(operate)列
                },
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'student.name', title: __('Student_Name'), operate: 'LIKE'},
                        {field: 'teacher.nickname', title: __('签到老师'), operate: 'LIKE'},
                        {field: 'buketeacher.nickname', title: __('补课老师'), operate: 'LIKE'},
                        {field: 'day', title: __('Day'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime,datetimeFormat:'YYYY-MM-DD'},
                        {field: 'status', title: __('Status'), searchList:Config.statusList,  formatter: Table.api.formatter.label},
                        {field: 'school_id', title: __('School'), searchList: Config.schoolGroup, formatter: Table.api.formatter.label},
                        {field: 'course.name', title: __('Course_Name'), operate: 'LIKE'},
                        {field: 'class_hour', title: __('课时'), operate: 'LIKE'},
                        {field: 'order_goods.time_name', title: __('Time_Name'), operate: false},
                        {field: 'leave_content', title: __('Leave_Content'), operate: false},

                        // {field: 'weigh', title: __('Weigh'), operate: false},
                        // {field: 'switch', title: __('Switch'), searchList: {"1":__('Yes'),"0":__('No')}, table: table, formatter: Table.api.formatter.toggle},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
                //选择用户
                $("#c-user_id").data("eSelect", function(){
                    //后续操作
                    $('#c-student_id').selectPageClear();
                    $('#c-day').val("");
                    $('#c-order_goods_id').selectPageClear();
                });
                //选择学员
                $("#c-student_id").data("eSelect", function(){
                    //后续操作
                    $('#c-day').val("");
                    $('#c-order_goods_id').selectPageClear();
                });
                //修改日期
                $("#c-day").on("dp.change", function(){
                    //回调事件
                    $('#c-order_goods_id').selectPageClear();
                });
                $("#c-student_id").data("params", function (obj) {
                    //obj为SelectPage对象
                    if($("#c-user_id").val()){
                        return {custom: {user_id: $("#c-user_id").val()}};
                    }

                });
                $("#c-order_goods_id").data("params", function (obj) {
                    //obj为SelectPage对象
                    return {custom: {student_id: $("#c-student_id").val(),day:$("#c-day").val()}};
                });
            }
        }
    };
    return Controller;
});
